package com.cssw.fyzb.web.controller;


import com.cssw.fyzb.base.web.context.UserContext;
import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.web.service.SysTextService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@ApiModel("文章相关接口")
@RestController
@RequestMapping("/text")
public class SysTextController {

    @Autowired
    SysTextService sysTextService;

    @ApiOperation(value = "文章分类列表", response = AjaxPage.class)
    @RequestMapping(value = "/listKind", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数", paramType = "query", dataType = "string", required = true),
    })
    public AjaxPage listKind(int page, int limit) {
        return sysTextService.listKind(page, limit);
    }


    @ApiOperation(value = "新增分类", response = AjaxData.class)
    @PostMapping(value = "/saveKind")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kindCode", value = "分类编码", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "kindName", value = "分类名称", paramType = "query", dataType = "string", required = true),
    })
    public AjaxData saveKind(String kindCode,String kindName) {
        return sysTextService.saveKind(kindCode,kindName,UserContext.getUserId());
    }


    @ApiOperation(value = "修改分类", response = AjaxData.class)
    @PostMapping(value = "/updateKind",headers = "content-type=multipart/form-data")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kindCode", value = "分类编码", paramType = "form", dataType = "string", required = true),
            @ApiImplicitParam(name = "kindName", value = "分类名称", paramType = "form", dataType = "string", required = true),
    })
    public AjaxData updateKind(String kindCode,String kindName) {
        return sysTextService.updateKind(kindCode,kindName,UserContext.getUserId());
    }

    @ApiOperation(value = "删除分类", response = AjaxData.class)
    @RequestMapping(value = "/deleteKind", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kindCode", value = "分类编码", paramType = "query", dataType = "string", required = true),
    })
    public AjaxData deleteKind(String kindCode) {
        return sysTextService.deleteKind(kindCode,UserContext.getUserId());
    }


    @ApiOperation(value = "文章列表", response = AjaxPage.class)
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数", paramType = "query", dataType = "string", required = true),
    })
    public AjaxPage list(int page, int limit) {
        return sysTextService.list(page, limit);
    }


    @ApiOperation(value = "新增文章", response = AjaxData.class)
    @PostMapping(value = "/save")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "textCode", value = "文本编码", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "textName", value = "文本名称", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "kindCode", value = "文本分类编码", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "content", value = "文本内容", paramType = "query", dataType = "string", required = false),
            @ApiImplicitParam(name = "textUrl", value = "url地址", paramType = "query", dataType = "string", required = false),
    })
    public AjaxData save(String textCode,String textName,String kindCode,String content,String textUrl) {
        return sysTextService.save(textCode,textName,kindCode,content,textUrl,UserContext.getUserId());
    }


    @ApiOperation(value = "修改文章", response = AjaxData.class)
    @PostMapping(value = "/update")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "textCode", value = "文本编码", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "textName", value = "文本名称", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "kindCode", value = "文本分类编码", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "content", value = "文本内容", paramType = "query", dataType = "string", required = false),
            @ApiImplicitParam(name = "textUrl", value = "url地址", paramType = "query", dataType = "string", required = false),
    })
    public AjaxData update(String textCode,String textName,String kindCode,String content,String textUrl) {
        return sysTextService.update(textCode,textName,kindCode,content,textUrl,UserContext.getUserId());
    }

    @ApiOperation(value = "删除文章", response = AjaxData.class)
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "textCode", value = "文本编码", paramType = "query", dataType = "string", required = true),
    })
    public AjaxData delete(String textCode) {
        return sysTextService.delete(textCode,UserContext.getUserId());
    }
}
